<?php

namespace App\Controllers\Admin;

use Page,Rate,View,Work;
use Input, Notification, Redirect, Sentry, Str;

use App\Services\Validators\PageValidator;

class RatesController extends \BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
        $user = Sentry::getUser();


        if ($user->hasAccess('admin')){
            $rates = Rate::orderBy('created_at', 'DESC')->paginate(20);
        }elseif($user->hasAccess('city')){
            $rates = Rate::where('city',$user->city)->orderBy('created_at', 'DESC')->paginate(20);
        }elseif($user->hasAccess('section')){
            $rates = Rate::where('area',$user->area)->orderBy('created_at', 'DESC')->paginate(20);
        }
        $works = Work::where('section_id',$user->area)->orderBy('created_at', 'DESC')->get();
        $METHOD = 'rates';
        $ACTION = 'index';
//        $services = Service::where('section_id',$user->area)->orderBy('created_at', 'DESC')->paginate(20);
//        $works = Work::where('section_id',$user->area)->orderBy('created_at', 'DESC')->get();
        return View::make('admin.rates.index',compact('METHOD','ACTION','rates','works'));

	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{


	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//

	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{

	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
        $rate = Rate::findOrFail($id);
        $rate->delete();
//        Flash::success(lang('Operation succeeded.'));

        return Redirect::route('rates.index');

	}

    public function export(){

    }

    protected function _excel($list)
    {

    }


}
